package com.company;


import org.apache.commons.lang3.time.DateUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


public class Task4 {
    private static String[] parsePatterns = {"yyyy-MM-dd","yyyy年MM月dd日",
            "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy/MM/dd",
            "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyyMMdd"};


    public static void main(String[] args) {
        //todo 写个方法，判断上/下午，boolean isAfternoon(String s)，调用方式，如：isAfternoon("2006-01-02 03:04:05")
        boolean b = isAfternoon("2006-01-02 03:04:05");
        System.out.println("现在是" + (b ?"上午":"下午" ));
    }

    public static boolean isAfternoon(String s){
        try {
            Date date = DateUtils.parseDate(s, parsePatterns);
            SimpleDateFormat df = new SimpleDateFormat("HH");
            String str = df.format(date);
            int a = Integer.parseInt(str);
            if (a > 0 && a <= 12) {
                return true;
            }
            if (a > 12 && a <= 24) {
                return false;
            }
        }catch (ParseException e) {
            e.printStackTrace();
        }
        return true;
    }
}
